<script setup lang="ts">
import { computed } from 'vue'
import TaskCard from './TaskCard.vue'

interface Props {
  title: string
  tasks: Array<{
    id: string
    title: string
    status: string
    assignee?: {
      id: number
      avatar: string
      name: string
    }
    dueDate?: string
    progress?: number
    priority?: string
  }>
}

const props = defineProps<Props>()
const emit = defineEmits<{
  (e: 'task-drop', taskId: string, status: string): void
}>()

// 计算任务数量
const taskCount = computed(() => props.tasks.length)

// 处理拖拽
const handleDrop = (e: DragEvent) => {
  e.preventDefault()
  if (!e.currentTarget) return
  
  const taskId = e.dataTransfer?.getData('text/plain')
  if (taskId) {
    emit('task-drop', taskId, props.title)
  }
  
  // 移除拖拽效果
  (e.currentTarget as HTMLElement).classList.remove('drag-over')
}

const handleDragOver = (e: DragEvent) => {
  e.preventDefault()
  if (!e.currentTarget) return
  ;(e.currentTarget as HTMLElement).classList.add('drag-over')
}

const handleDragLeave = (e: DragEvent) => {
  e.preventDefault()
  ;(e.currentTarget as HTMLElement).classList.remove('drag-over')
}
</script>

<template>
  <div 
    class="task-column"
    @drop="handleDrop"
    @dragover="handleDragOver"
    @dragleave="handleDragLeave"
  >
    <div class="column-header">
      <div class="title-section">
        <span class="title">{{ title }}</span>
        <span class="count">{{ taskCount }}</span>
      </div>
      <div class="actions">
        <i class="el-icon-plus"></i>
        <i class="el-icon-more"></i>
      </div>
    </div>
    
    <div class="tasks-container">
      <template v-for="task in tasks" :key="task.id">
        <slot :task="task">
          <TaskCard v-bind="task" />
        </slot>
      </template>
    </div>
  </div>
</template>

<style scoped>
.task-column {
  flex: 1;
  min-width: 280px;
  background: #eef0f6;
  border-radius: 8px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: all 0.3s ease;
  height: fit-content;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.task-column.drag-over {
  background: #e6efff;
  border: 2px dashed #409eff;
  box-shadow: 0 6px 16px rgba(64, 158, 255, 0.2);
  transform: translateY(-2px);
}

.column-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.title-section {
  display: flex;
  align-items: center;
  gap: 8px;
}

.title {
  font-weight: 500;
  color: #303133;
}

.count {
  background: #e4e7ed;
  color: #606266;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
}

.actions {
  display: flex;
  gap: 8px;
  color: #909399;
}

.actions i {
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: all 0.3s;
}

.actions i:hover {
  background: #e4e7ed;
  color: #606266;
}

.tasks-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: visible;
  padding-right: 4px;
}

.tasks-container::-webkit-scrollbar {
  display: none;
}

.tasks-container::-webkit-scrollbar-thumb {
  display: none;
}

.tasks-container::-webkit-scrollbar-track {
  display: none;
}
</style> 